using System; using System.Collections.Generic; using Shared.SimpleControl; namespace Shared.SimpleControl.Phone { public class UserCurtainPage : FrameLayout { /// /// 当前打开的窗帘界面 /// public static UserCurtainPage curView; FrameLayout roomBackgroundImage; Common curtain; Button btnCloseCurtain; Button btnOpenCurtain; Button btnStopCurtain; Button btnCurrentStatus; Button btnTitle; HorizontalSeekBar horizontalSeekBar; Room room; /// /// 显示当前房间窗帘设备 /// public UserCurtainPage (Common curtain, Room Room) { this.curtain = curtain; BackgroundColor = SkinStyle.Current.MainColor; room = Room; curView = this; } /// /// 接受到窗帘发出的数据之后更新UI /// 窗帘停止回复的命令没有必要调用UpdateStatus /// /// The user lights. public static void UpdateStatus (Common curtain) { Application.RunOnMainThread (() => { if (curView == null || curView.curtain != curtain) { return; } if (curView.curtain.Type == DeviceType.CurtainTrietex) { var curtainTrietex = curView.curtain as CurtainTrietex; //不在模拟进度时 if (curView.th == null) { curView.btnCurrentStatus.Text = curtainTrietex.CurtainProress.ToString () + "%"; curView.horizontalSeekBar.Progress = curtainTrietex.CurtainProress; } } else if (curView.curtain.Type == DeviceType.CurtainRoller) { var curtainRoller = curView.curtain as CurtainRoller; //不在模拟进度时 if (curView.th == null) { curView.btnCurrentStatus.Text = curtainRoller.CurtainProress.ToString () + "%"; curView.horizontalSeekBar.Progress = curtainRoller.CurtainProress; } } else if (curView.curtain.Type == DeviceType.CurtainModel) { var curtainModel = curView.curtain as CurtainModel; if (curView.th == null) { switch(curtainModel.Status) { case CurtainStatus.Stop: curView.btnStopCurtain.IsSelected = true; curView.btnOpenCurtain.IsSelected = false; curView.btnCloseCurtain.IsSelected = false; break; case CurtainStatus.Open: curView.btnStopCurtain.IsSelected = false; curView.btnOpenCurtain.IsSelected = true; curView.btnCloseCurtain.IsSelected = false; break; case CurtainStatus.Close: curView.btnStopCurtain.IsSelected = false; curView.btnOpenCurtain.IsSelected = false; curView.btnCloseCurtain.IsSelected = true; break; } } } }); } /// /// 房间模式进入的窗帘界面 /// /// The lights room. public void showCurtainsRoom () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (640), }; AddChidren (topView); btnTitle = new Button () { TextAlignment = TextAlignment.Center, Text = room.Name, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (btnTitle); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; curView = null; }; #endregion roomBackgroundImage = new FrameLayout () { Y = topView.Bottom, Height = MainPage.GetDesignHeight (360), }; AddChidren (roomBackgroundImage); roomBackgroundImage.BackgroundImagePath = room.BackGroundImage; #if wallon #else roomBackgroundImage.MouseLongEventHandler += (sender, e) => { Camera.SelectPicture ((obj) => { if (obj != null) { room.BackGroundImage = obj; roomBackgroundImage.BackgroundImagePath = obj; room.Save (typeof (Room).Name + "_" + room.Name); } }, room.Name, false); }; #endif if (curtain.Type == DeviceType.CurtainModel) { addCurtainModeul ( curtain as CurtainModel); } else if (curtain.Type == DeviceType.CurtainTrietex) { AddCurtainTrietex ( curtain as CurtainTrietex); } else if (curtain.Type == DeviceType.CurtainRoller) { AddCurtainRoller ( curtain as CurtainRoller); } Control.ControlBytesSend (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { curtain.LoopID }); } /// /// 加载窗帘的模块按钮界面 /// void addCurtainModeul ( CurtainModel curtainMode) { btnTitle.Text = curtainMode.Name; var curtainView = new FrameLayout () { Height = Application.GetRealHeight (400), Width = Application.GetRealWidth(640), Y = roomBackgroundImage.Bottom, }; AddChidren (curtainView); btnOpenCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (80), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Curtain/CurtainOpen.png", SelectedImagePath = "Curtain/CurtainOpenSelected.png", }; curtainView.AddChidren (btnOpenCurtain); btnStopCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth ((640 - 124) / 2), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; curtainView.AddChidren (btnStopCurtain); btnCloseCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (640 - 80 - 124), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainClose.png", SelectedImagePath = "Curtain/CurtainCloseSelected.png", }; curtainView.AddChidren (btnCloseCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Open, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnOpenLbl); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnStopLbl); var btnCloseLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Close2, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnCloseLbl); btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => { curtainMode.Status = CurtainStatus.Close; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainMode.SubnetID, curtainMode.DeviceID, new byte [] { curtainMode.LoopID, 2 }); (sender3 as Button).IsSelected = true; btnOpenCurtain.IsSelected = false; btnStopCurtain.IsSelected = false; }; btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => { curtainMode.Status = CurtainStatus.Open; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainMode.SubnetID, curtainMode.DeviceID, new byte [] { curtainMode.LoopID, 1 }); (sender3 as Button).IsSelected = true; btnCloseCurtain.IsSelected = false; btnStopCurtain.IsSelected = false; }; btnStopCurtain.MouseDownEventHandler += (sender3, e3) => { curtainMode.Status = CurtainStatus.Stop; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainMode.SubnetID, curtainMode.DeviceID, new byte [] { curtainMode.LoopID, 0 }); (sender3 as Button).IsSelected = true; btnOpenCurtain.IsSelected = false; btnCloseCurtain.IsSelected = false; }; if (curtainMode.Status == CurtainStatus.Close) { btnCloseCurtain.IsSelected = true; } else if (curtainMode.Status == CurtainStatus.Open) { btnOpenCurtain.IsSelected = true; } else { btnStopCurtain.IsSelected = true; } } /// /// 加载开合帘界面 /// void AddCurtainTrietex ( CurtainTrietex curtainTrietex) { btnTitle.Text = curtainTrietex.Name; #region 进度条 FrameLayout progressControlView = new FrameLayout () { Height = Application.GetRealHeight (320), BackgroundColor = SkinStyle.Current.ViewColor, Width = Application.GetRealWidth(640), Y = roomBackgroundImage.Bottom, }; AddChidren (progressControlView); Button btnCurrentIcon = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), UnSelectedImagePath = "Curtain/curtain1.png", }; progressControlView.AddChidren (btnCurrentIcon); Button btnCurrentStatusText = new Button () { X = btnCurrentIcon.Right, Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (105), TextID = R.MyInternationalizationString.CurrentStatus, TextAlignment = TextAlignment.CenterLeft }; progressControlView.AddChidren (btnCurrentStatusText); FrameLayout trietexProgressView = new FrameLayout () { Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (60), Y = Application.GetRealHeight (150), }; progressControlView.AddChidren (trietexProgressView); horizontalSeekBar = new HorizontalSeekBar () { Progress = curtainTrietex.CurtainProress, ThumbColor = SkinStyle.Current.ThumbColor, ProgressColor = SkinStyle.Current.SelectedColor }; trietexProgressView.AddChidren (horizontalSeekBar); btnCurrentStatus = new Button () { Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (60), X = trietexProgressView.Right, Y = trietexProgressView.Y, Text = curtainTrietex.CurtainProress.ToString () + "%", TextColor = SkinStyle.Current.TextColor1, }; progressControlView.AddChidren (btnCurrentStatus); horizontalSeekBar.ProgressChanged += (sender, e) => { btnCurrentStatus.Text = e.ToString () + "%"; curtainTrietex.CurtainProress = (byte)e; }; horizontalSeekBar.MouseDownEventHandler += (sender, e) => { stop (); }; horizontalSeekBar.MouseUpEventHandler += (sender, e) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 17, Convert.ToByte (horizontalSeekBar.Progress) }); btnCurrentStatus.Text = curtainTrietex.CurtainProress.ToString () + "%"; th = new System.Threading.Thread ((obj) => { //如果后面没有什么操作,到时自动还原接收更新状态 System.Threading.Thread.Sleep (20 * 1000); th = null; }); th.Start (); }; #endregion FrameLayout curtainView = new FrameLayout () { Height = Application.GetRealHeight (350), Y = progressControlView.Bottom + Application.GetRealHeight(3), BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (curtainView); btnOpenCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (40), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Curtain/CurtainOpen.png", SelectedImagePath = "Curtain/CurtainOpenSelected.png", }; curtainView.AddChidren (btnOpenCurtain); btnStopCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth ((640 - 124) / 2), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; curtainView.AddChidren (btnStopCurtain); btnCloseCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (640 - 40 - 124), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainClose.png", SelectedImagePath = "Curtain/CurtainCloseSelected.png", }; curtainView.AddChidren (btnCloseCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Open, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnOpenLbl); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnStopLbl); var btnCloseLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Close2, TextColor = SkinStyle.Current.TextColor1, }; curtainView.AddChidren (btnCloseLbl); btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 1, 2 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainTrietex.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress - (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainTrietex.Speed); v = v < 0 ? 0 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (v <= 0) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全开状态,这样初始化的值会是比较准确的 if (90 <= startProgress) { intSpped (0); } } }; btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 1, 1 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainTrietex.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress + (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainTrietex.Speed); v = 100 < v ? 100 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (100 <= v) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全关状态,这样初始化的值会是比较准确的 if (startProgress <= 10) { intSpped (100); } } }; btnStopCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainTrietex.SubnetID, curtainTrietex.DeviceID, new byte [] { 1, 0 }); stop (); }; statrtReadProgress (); } /// /// 结束值 /// /// V. void intSpped (int v) { MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.Initiating)); DateTime dateTime = DateTime.Now; System.Threading.Tasks.Task.Run (() => { while (curView != null) { System.Threading.Thread.Sleep (500); var bytes = Control.ControlBytesSendHasReturn (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { 17 }); if (bytes == null) { break; } else { if (2 <= bytes.Length && v == bytes [1]) { if (curtain.Type == DeviceType.CurtainRoller) { (curtain as CurtainRoller).Speed = 100 / ((DateTime.Now - dateTime).TotalMilliseconds - 300); } else if (curtain.Type == DeviceType.CurtainTrietex) { (curtain as CurtainTrietex).Speed = 100 / ((DateTime.Now - dateTime).TotalMilliseconds - 300); } break; } } } Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); }); } void stop () { try { if (th != null) { th.Abort (); th = null; //Control.ControlBytesSend (Command.ReadCurtainStatus, curtain.SubnetID, curtain.DeviceID, new byte [] { 17 }); } } catch { } } /// /// 加载卷帘界面 /// void AddCurtainRoller (CurtainRoller curtainRoller) { btnTitle.Text = curtainRoller.Name; #region 进度条 FrameLayout ProgressControlView = new FrameLayout () { Height = Application.GetRealHeight (320), BackgroundColor = SkinStyle.Current.ViewColor, Y = roomBackgroundImage.Bottom, }; AddChidren (ProgressControlView); Button btnCurrentIcon = new Button () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (105), Height = Application.GetRealHeight (105), UnSelectedImagePath = "Curtain/rollerCurtain.png", }; ProgressControlView.AddChidren (btnCurrentIcon); Button btnCurrentStatusText = new Button () { X = btnCurrentIcon.Right, Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (105), TextID = R.MyInternationalizationString.CurrentStatus, TextAlignment = TextAlignment.CenterLeft }; ProgressControlView.AddChidren (btnCurrentStatusText); FrameLayout rollerProgressView = new FrameLayout () { Width = Application.GetRealWidth (480), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (60), Y = Application.GetRealHeight (150), }; ProgressControlView.AddChidren (rollerProgressView); horizontalSeekBar = new HorizontalSeekBar () { Height = LayoutParams.MatchParent, Gravity = Gravity.CenterVertical, Progress = curtainRoller.CurtainProress, ThumbColor = SkinStyle.Current.ThumbColor, }; rollerProgressView.AddChidren (horizontalSeekBar); btnCurrentStatus = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (60), X = rollerProgressView.Right, Y = rollerProgressView.Y, Text = curtainRoller.CurtainProress.ToString () + "%", TextColor = SkinStyle.Current.TextColor1, }; ProgressControlView.AddChidren (btnCurrentStatus); horizontalSeekBar.ProgressChanged += (sender, e) => { btnCurrentStatus.Text = e.ToString () + "%"; curtainRoller.CurtainProress = (byte)e; }; horizontalSeekBar.MouseDownEventHandler += (sender, e) => { stop (); }; horizontalSeekBar.MouseUpEventHandler += (sender, e) => { Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 17, Convert.ToByte (horizontalSeekBar.Progress) }); btnCurrentStatus.Text = curtainRoller.CurtainProress.ToString () + "%"; th = new System.Threading.Thread ((obj) => { //如果后面没有什么操作,到时自动还原接收更新状态 System.Threading.Thread.Sleep (20 * 1000); th = null; }); th.Start (); }; #endregion FrameLayout rollerView = new FrameLayout () { Y =ProgressControlView.Bottom + Application.GetRealHeight(3), Height = Application.GetRealHeight (350), BackgroundColor = SkinStyle.Current.ViewColor, }; rollerView.AddTag ("UpdataKey", curtainRoller.SubnetID.ToString () + curtainRoller.DeviceID.ToString () + curtainRoller.LoopID.ToString ()); AddChidren (rollerView); btnOpenCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (40), Y = Application.GetRealHeight (50), UnSelectedImagePath = "Curtain/CurtainRollerUp.png", SelectedImagePath = "Curtain/CurtainRollerUpOn.png", }; rollerView.AddChidren (btnOpenCurtain); btnStopCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), Gravity = Gravity.CenterHorizontal, Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainTimeOut.png", SelectedImagePath = "Curtain/CurtainTimeOutSelected.png", }; rollerView.AddChidren (btnStopCurtain); btnCloseCurtain = new Button () { Width = Application.GetMinRealAverage (124), Height = Application.GetMinRealAverage (124), X = Application.GetRealWidth (640 - 40 - 124), Y = btnOpenCurtain.Y, UnSelectedImagePath = "Curtain/CurtainRollerDown.png", SelectedImagePath = "Curtain/CurtainRollerDownOn.png", }; rollerView.AddChidren (btnCloseCurtain); var btnOpenLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnOpenCurtain.X, Y = btnOpenCurtain.Bottom + Application.GetRealHeight (5), TextID = R.MyInternationalizationString.Up, TextColor = SkinStyle.Current.TextColor1, }; rollerView.AddChidren (btnOpenLbl); var btnStopLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnStopCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Stop, TextColor = SkinStyle.Current.TextColor1, }; rollerView.AddChidren (btnStopLbl); var btnCloseLbl = new Button () { Width = Application.GetRealWidth (124), Height = Application.GetRealHeight (30), X = btnCloseCurtain.X, Y = btnOpenLbl.Y, TextID = R.MyInternationalizationString.Down, TextColor = SkinStyle.Current.TextColor1, }; rollerView.AddChidren (btnCloseLbl); btnCloseCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 1, 2 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainRoller.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress - (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainRoller.Speed); v = v < 0 ? 0 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (v <= 0) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全开状态,这样初始化的值会是比较准确的 if (90 <= startProgress) { intSpped (0); } } }; btnOpenCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 1, 1 }); stop (); int startProgress = horizontalSeekBar.Progress; if (0 < curtainRoller.Speed) { th = new System.Threading.Thread ((obj) => { var startDateTime = DateTime.Now; while (curView != null) { System.Threading.Thread.Sleep (200); var v = startProgress + (int)((DateTime.Now - startDateTime).TotalMilliseconds * curtainRoller.Speed); v = 100 < v ? 100 : v; Application.RunOnMainThread (() => { horizontalSeekBar.Progress = v; btnCurrentStatus.Text = v + "%"; }); if (100 <= v) { break; } } //防止跳动 System.Threading.Thread.Sleep (2000); th = null; }); th.Start (); } else { readProgressDateTime = DateTime.Now; //接近全关状态,这样初始化的值会是比较准确的 if (startProgress <= 10) { intSpped (100); } } }; btnStopCurtain.MouseDownEventHandler += (sender3, e3) => { (sender3 as Button).IsSelected = true; Control.ControlBytesSend (Command.UpdataCurtainModelStutas, curtainRoller.SubnetID, curtainRoller.DeviceID, new byte [] { 1, 0 }); stop (); }; } DateTime readProgressDateTime = System.DateTime.MaxValue; System.Threading.Thread th; void statrtReadProgress () { int endProgress = 0; System.Threading.Tasks.Task.Run (() => { if (curtain.Type == DeviceType.CurtainRoller) { var curtainroller = curtain as CurtainRoller; Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 }); } else if (curtain.Type == DeviceType.CurtainTrietex) { var curtaintrietex = curtain as CurtainTrietex; Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 }); } while (curView != null) { System.Threading.Thread.Sleep (300); if (readProgressDateTime == DateTime.MaxValue) { continue; } if (curtain.Type == DeviceType.CurtainRoller) { var curtainroller = curtain as CurtainRoller; if (curtainroller.CurtainProress != endProgress) { endProgress = curtainroller.CurtainProress; readProgressDateTime = DateTime.Now; } if ((DateTime.Now - readProgressDateTime).TotalMilliseconds < 1000) { Control.ControlBytesSend (Command.ReadCurtainStatus, curtainroller.SubnetID, curtainroller.DeviceID, new byte [] { 17 }, SendCount.Zero); } else { readProgressDateTime = DateTime.MaxValue; } } else if (curtain.Type == DeviceType.CurtainTrietex) { var curtaintrietex = curtain as CurtainTrietex; if (curtaintrietex.CurtainProress != endProgress) { endProgress = curtaintrietex.CurtainProress; readProgressDateTime = DateTime.Now; } if ((DateTime.Now - readProgressDateTime).TotalMilliseconds < 1000) { Control.ControlBytesSend (Command.ReadCurtainStatus, curtaintrietex.SubnetID, curtaintrietex.DeviceID, new byte [] { 17 }, SendCount.Zero); } else { readProgressDateTime = DateTime.MaxValue; } } } }); } } }